<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>黑马书籍商城--牛人书店</title>
		<script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
		<script type="text/javascript">
			$(function(){
				$("#all").click(function(){
					$("#context input[type='checkbox']").prop("checked",$(this).prop("checked"));
				});
				
				$("#ref").click(function(){
					$("#context input[type='checkbox']").each(function(i,n){
						if($(n).prop("checked")){
							$(n).prop("checked",false);
						}else{
							$(n).prop("checked",true);
						}
					});					
				});
				$("#deleteAll").click(function(){
					var ids = "";
					$("#context :checkbox:checked").each(function(i,n){
						ids += $(n).val()+",";
					});
					if(ids == ""){
						alert("请选择删除的数据！！！！");
						return false;
					}else{
						if(confirm("您是否确认删除选中的数据！！！")){
							ids = ids.substring(0,ids.length-1);
							location.href="${pageContext.request.contextPath}/BookServlet?method=deleteAll&ids="+ids;
						}
					}	
				});
				$(".deleteitem").click(function(){
					//alert($(this).attr("data-id"));
					var bid = $(this).data("id");					
					if(confirm("您确定删除该条数据？")){
						location.href="${pageContext.request.contextPath}/BookServlet?method=delete&bid="+bid;
					}
				});
			});
		</script>
	</head>
	<body>
		
		<h3 style="text-align: center;">黑马书籍商城--牛人书店</h3>
		<p style="text-align: center;">
			欢迎尊贵的铂金会员
			<span style="color: red;">
			 	${existUser.name}
			</span> 
			<a href="${pageContext.request.contextPath}/CartServlet?method=findByPage">分页查询</a>
			<a href="${pageContext.request.contextPath}/CartServlet?method=findAll">购物车</a>
			<a href="${pageContext.request.contextPath}/LogoutServlet">[退出登录]</a>
		</p>
		<center style="color:red;font-size:20px">
			${tip}
		</center>
		<hr />		
		<table border="1" align="center">
			<thead>
				
				<tr>
					
					<td colspan="7">
						<form action="${pageContext.request.contextPath}/BookServlet?method=search" method="post">
							书籍名称：<input type="text" name="bookName" />
							价格:<input type="text" name="s_price" /> 至 <input type="text" name="e_price" />
							<input type="submit" value="查询" />
						</form>
					</td>
				</tr>
				<tr>
					<td colspan="7">
						<a href="${pageContext.request.contextPath}/BookServlet?method=add">添加</a>
						<a href="javascript:void(0);" id="deleteAll">删除选中</a>
					</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="all"/>全选 &nbsp;&nbsp; <input type="checkbox" id="ref"/> 反选</th>
					<th>id</th>
					<th>书籍名称</th>
					<th>作者</th>
					<th>价格</th>
					<th>备注</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="context">				
				<c:forEach var="book" items="${ books }">
				<tr>
					<td style="text-align:center"><input type="checkbox" name="ids" value="${book.bid}"/></td>
					<td>${book.bid}</td>
					<td>${book.bookName}</td>
					<td>${book.author}</td>
					<td>${book.price}</td>
					<td>${book.b_desc}</td>
					<td>
						<a href="javascript:void(0);" class="deleteitem" data-id="${book.bid}" >删除</a>
						&nbsp;&nbsp;&nbsp;
						<a href="${pageContext.request.contextPath}/BookServlet?method=edit&bid=${book.bid}">修改</a>
						&nbsp;&nbsp;&nbsp;
						<a href="${pageContext.request.contextPath}/CartServlet?method=add&bid=${book.bid}">加入购物车</a>
					</td>
				</tr>
				</c:forEach>
			</tbody>
		</table>
		
	</body>
</html>
